home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / bsrc_p1.arc / CDOG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-11-30  |  13.5 KB  |  513 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*               The Opus Computer-Based Conversation System                */
  3. /*       (c) Copyright 1987, Wynn Wagner III, All Rights Reserved           */
  4. /*                                                                          */
  5. /*                   YOOHOO is a trademark of Wynn Wagner III               */
  6. /*                                                                          */
  7. /*                            YOOHOO-YOOHOO/2U2 is                          */
  8. /*           Copyright 1987, Wynn Wagner III, All Rights Reserved           */
  9. /*                                                                          */
  10. /*                 This module was written by Bob Hartman                   */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                BinkleyTerm SEAdog Mail Session Routines                  */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*  This module is a very simple FOSSIL-based terminal emulator. It is      */
  17. /*  provided for your information only.  You will find routines that need   */
  18. /*  to be coded and identifiers to be resolved. It has been previously      */
  19. /*  known as "OpusLink" and "OConnect". The use of the name "BinkleyTerm"   */
  20. /*  does not preclude the possibility that another "OpusLink" or "OConnect" */
  21. /*  could be released.                                                      */
  22. /*                                                                          */
  23. /*  There is absolutely no guarantee that anything here will work.  If you  */
  24. /*  break this routine, you own both pieces.                                */
  25. /*                                                                          */
  26. /*  USAGE:  You may use this material in any program with no obligation     */
  27. /*          as long as there is no charge for your program.  For more       */
  28. /*          information about commercial use, contact the "OPUSinfo HERE"   */
  29. /*          BBS (124/111).                                                  */
  30. /*                                                                          */
  31. /*                                                                          */
  32. /*--------------------------------------------------------------------------*/
  33.  
  34. #include <signal.h>
  35. #include <ctype.h>
  36. #include <conio.h>
  37. #include <time.h>
  38.  
  39. #define WAZOO_SECTION
  40. #define MATRIX_SECTION
  41.  
  42. #define MYPRODUCT 0x0f
  43.  
  44. #include "zmodem.h"
  45. #include "com.h"
  46. #define rb_plus "rb+"
  47.  
  48. extern char *BUNDLE_msg;
  49. extern char *FIND_msg;
  50. extern char *WRITE_msg;
  51. extern char *FLAGGING_msg;
  52. extern char *TRUNC_msg;
  53.  
  54. extern char *ext_flags;       /* Change to whatever, and */
  55. extern int net_problems;        /* This should be external */
  56. extern char no_pickup;
  57. extern int remote_net, remote_node;
  58. extern int called_net, called_node;
  59. extern char *remote_password;
  60. extern char no_requests;
  61. extern int n_requests;
  62. extern long timezone;
  63.  
  64. SEA_sendreq ()
  65. {
  66.    char fname[80];
  67.    char reqf[80];
  68.    char *p, *name, *pw;
  69.    int i, j, done, done1, nfiles;
  70.    unsigned int crc;
  71.    FILE *fp;
  72.    long t1, timerset();
  73.  
  74.  
  75.    t1 = timerset (1000);
  76.  
  77.    sprintf( fname,
  78.             "%s%04x%04x.REQ",
  79.             ctl.hold_area,called_net,called_node);
  80.    errno = 0;
  81.  
  82.    /* If we have file requests, then do them */
  83.    if (stat(fname,reqf))
  84.       {
  85.       status_line (":No outgoing file requests");
  86.       }
  87.    else
  88.       {
  89.       status_line (":Outbound file requests");
  90.       /* Open the .REQ file */
  91.       if ((fp = fopen (fname, "r")) == NULL)
  92.          {
  93.          SENDBYTE(ETB);
  94.          return (1);
  95.          }
  96.  
  97.       /* As long as we do not have EOF, read the request */
  98.       while ((fgets (reqf, 79, fp) != NULL) && (CARRIER))
  99.          {
  100.          /* Properly format the request */
  101.  
  102.          /* First get rid of the trailing junk */
  103.          p = reqf+strlen(reqf)-1;
  104.          while ((p>=reqf)&&(isspace(*p)))
  105.             *p-- = '\0';
  106.  
  107.          /* Now get rid of the beginning junk */
  108.          p = reqf;
  109.          while ((*p) && (isspace (*p)))
  110.             p++;
  111.          /* This is where the name starts */
  112.          name = p;
  113.  
  114.          /* If the first char is ; then ignore the line */
  115.          if (*name == ';')
  116.             continue;
  117.  
  118.          /* Now get to where the name ends */
  119.          while ((*p) && (!isspace (*p)))
  120.             p++;
  121.          if (*p)
  122.             {
  123.             *p = '\0';
  124.             ++p;
  125.             while ((*p) && (*p != '!'))
  126.                p++;
  127.             if (*p == '!')
  128.                {
  129.                *p = ' ';
  130.                }
  131.             pw = p;
  132.             }
  133.          else
  134.             {
  135.             pw = p;
  136.             }
  137.  
  138.          if (req_out (name, pw))
  139.             continue;
  140.  
  141.          /* Wait for ACK or ENQ */
  142.          t1 = timerset (1000);
  143.          done = 0;
  144.          while ((!timeup (t1)) && CARRIER && !done)
  145.             {
  146.             j = TIMED_READ(0);
  147.             if (j >= 0)
  148.                {
  149.                if (j == ACK)
  150.                   {
  151.                   /* If ACK, receive files using SEAlink */
  152.                   nfiles = 0;
  153.                   done1 = 0;
  154.                   do
  155.                      {
  156.                      if ((i = try_sealink ()) == 0)
  157.                         {
  158.                         if (!recvmdm7 (reqf))
  159.                            {
  160.                            done1 = 1;
  161.                            }
  162.                         else
  163.                            {
  164.                            if (!receive_file (ctl.filepath, NULL, 'T'))
  165.                               {
  166.                               if (locate_y>1) gotoxy(0,locate_y-1);
  167.                               done1 = 1;
  168.                               }
  169.                            else
  170.                               ++nfiles;
  171.                            }
  172.                         }
  173.                      else if (i == 1)
  174.                         {
  175.                         if (!receive_file (ctl.filepath, NULL, 'F'))
  176.                            {
  177.                            if (locate_y>1) gotoxy(0,locate_y-1);
  178.                            done1 = 1;
  179.                            }
  180.                         else
  181.                            ++nfiles;
  182.                         }
  183.                      else
  184.                         {
  185.                         done1 = 1;
  186.                         }
  187.  
  188.                      } while (CARRIER && !done1);
  189.  
  190.                   status_line (":Received %d files", nfiles);
  191.                   done = 1;
  192.                   t1 = timerset (1000);
  193.  
  194.                   /* wait for request start */
  195.                   while ((TIMED_READ(0) != ENQ) && (!timeup (t1)) && CARRIER)
  196.                      time_release();
  197.                   }
  198.                else if (j == ENQ)
  199.                   {
  200.                   /* If ENQ, report no files received */
  201.                   req_out (name, pw);
  202.                   }
  203.                else
  204.                   {
  205.                   time_release();
  206.                   }
  207.                }
  208.             }
  209.          }
  210.       fclose (fp);
  211.       unlink (fname);
  212.       status_line (":End of outbound file requests");
  213.       }
  214.  
  215.    /* Finish the file requests off */
  216.    SENDBYTE(ETB);
  217. }
  218.  
  219. SEA_recvreq ()
  220. {
  221.    int done;
  222.    int i, j;
  223.    int recno;
  224.    int retval;
  225.    int nfiles;
  226.    int nfiles1;
  227.    char p;
  228.    char *ptr;
  229.    char reqs[64];
  230.    char req[64];
  231.    long t1, timerset();
  232.    char *n_frproc();
  233.  
  234.    t1 = timerset (2000);
  235.  
  236.    if (no_requests)
  237.       {
  238.       /* Refuse file requests */
  239.       SENDBYTE(CAN);
  240.       status_line ("*Refusing inbound file requests");
  241.       return TRUE;
  242.       }
  243.  
  244.    /* Try the bark stuff */
  245.    done = 0;
  246.    nfiles = 0;
  247.    status_line (":Inbound file requests");
  248.    while (CARRIER && !done && (!timeup (t1)))
  249.       {
  250.       /* Send out the start signal */
  251.       SENDBYTE(ENQ);
  252.  
  253.       /* Wait for the response */
  254.       j = TIMED_READ(2);
  255.  
  256.       switch (j)
  257.          {
  258.          case ACK:
  259.             recno = -1;
  260.             nfiles1 = 0;
  261.             if ((retval = get_req_str (reqs, req, &recno)) > 0)
  262.                {
  263.                SENDBYTE(ACK);
  264.                do
  265.                   {
  266.                   if (reqs[0])
  267.                      i = xfermdm7 (reqs);
  268.                   else
  269.                      i = 2;
  270.  
  271.                   p = 'T';
  272.                   if (i == 0)
  273.                      {
  274.                      net_problems = 1;
  275.                      continue;
  276.                      }
  277.                   else if (i == 2)
  278.                      p = 'F';
  279.  
  280.                   if (retval == 1)
  281.                      {
  282.                      send_file (reqs, p);
  283.                      ++nfiles;
  284.                      ++nfiles1;
  285.                      }
  286.                   if (nfiles > n_requests)
  287.                      {
  288.                      status_line ("!File Request limit exceeded");
  289.                      recno = -1;
  290.                      }
  291.                   else if (gen_req_name (reqs, req, &recno) == 2)
  292.                      {
  293.                      recno = -1;
  294.                      }
  295.                   } while (CARRIER && (recno >= 0));
  296.  
  297.                if (retval != 1)
  298.                   {
  299.                   send_file (NULL, 'S');
  300.                   }
  301.                status_line (":%d matching files sent", nfiles1);
  302.                }
  303.             t1 = timerset (2000);
  304.             break;
  305.  
  306.          case ETB:
  307.          case ENQ:
  308.             done = 1;
  309.             break;
  310.  
  311.          case 'C':
  312.          case NAK:
  313.             SENDBYTE(EOT);
  314.             CLEAR_INBOUND();
  315.             break;
  316.          }
  317.       }
  318.    status_line (":End of inbound file requests");
  319.    return TRUE;
  320. }
  321.  
  322. try_sealink ()
  323. {
  324.    int i, j;
  325.    long t1, timerset();
  326.  
  327.    for (i = 0; i < 5; i++)
  328.       {
  329.       SENDBYTE ('C');
  330.  
  331.       t1 = timerset (100);
  332.       while (!timeup (t1) && CARRIER)
  333.          {
  334.          if ((j = PEEKBYTE()) >= 0)
  335.             {
  336.             if (j == SOH)
  337.                return (1);
  338.             j = TIMED_READ(0);
  339.             if (j == EOT)
  340.                return (2);
  341.             else if (j == TSYNC)
  342.                return (0);
  343.             }
  344.          else
  345.             {
  346.             time_release();
  347.             }
  348.          }
  349.  
  350.       if (!CARRIER)
  351.          break;
  352.       }
  353.  
  354.    return (0);
  355. }
  356.  
  357. req_out (name, pw)
  358. char *name, *pw;
  359. {
  360.    char *p;
  361.    char buf[80];
  362.    unsigned int crc;
  363.  
  364.    /* send the request */
  365.    p = name;
  366.    if (!*p)
  367.       return (1);
  368.  
  369.    status_line ("*Requesting '%s' %s%s", name, (*pw)?"with password":"", pw);
  370.    SENDBYTE(ACK);
  371.    crc = 0;
  372.    while (*p)
  373.       {
  374.       SENDBYTE(*p);
  375.       crc = xcrc(crc,(byte )(*p));
  376.       ++p;
  377.       }
  378.  
  379.    /* This is for straight requests being the standard */
  380.    SENDBYTE(' ');
  381.    crc = xcrc(crc,(byte )(' '));
  382.    SENDBYTE('0');
  383.    crc = xcrc(crc,(byte )('0'));
  384.    p = pw;
  385.    while (*p)
  386.       {
  387.       SENDBYTE(*p);
  388.       crc = xcrc(crc,(byte )(*p));
  389.       ++p;
  390.       }
  391.  
  392.    SENDBYTE(ETX);
  393.    crc = crc_finish(crc);
  394.    SENDBYTE( crc&0xff );
  395.    SENDBYTE( crc>>8   );
  396.    return (0);
  397. }
  398.  
  399. get_req_str (reqs, req, recno)
  400. char *reqs, *req;
  401. int *recno;
  402. {
  403.    unsigned int crc, crc1, crc2, crc3;
  404.    int i,j;
  405.  
  406.    crc = i = 0;
  407.    while (CARRIER)
  408.       {
  409.       j = TIMED_READ(2);
  410.       if (j < 0)
  411.          return (0);
  412.  
  413.       if (j == ETX)
  414.          {
  415.          crc1 = TIMED_READ(2);
  416.          crc2 = TIMED_READ(2);
  417.          crc3 = (crc2<<8)+crc1;
  418.          if (crc3 != crc)
  419.             {
  420.             status_line("!Bad crc - trying again");
  421.             return (0);
  422.             }
  423.          req[i] = '\0';
  424.          return (gen_req_name (reqs, req, recno));
  425.          }
  426.       else
  427.          {
  428.          req[i++] = j&0xff;
  429.          crc = xcrc (crc,j&0xff);
  430.          }
  431.       }
  432.    return (0);
  433. }
  434.  
  435. gen_req_name (reqs, req, recno)
  436. char *reqs, *req;
  437. int *recno;
  438. {
  439.    char *q, *q1;
  440.    struct stat  st;
  441.    extern char *n_frproc();
  442.    char         buf[32];
  443.    byte        *rqname;
  444.    long         fsecs, atol();
  445.    int          save_rec;
  446.  
  447.    save_rec = *recno;
  448.    q = req;
  449.    q1 = buf;
  450.    /* Get the filename */
  451.    while ((*q) && (!isspace(*q)))
  452.       {
  453.       *q1++ = *q++;
  454.       }
  455.  
  456.    /* If we have more characters, go on */
  457.    if (*q)
  458.       {
  459.       /* Skip the space */
  460.       ++q;
  461.  
  462.       fsecs = atol (q);
  463.  
  464.       /* Skip the digits */
  465.       while ((*q) && isdigit (*q))
  466.          ++q;
  467.  
  468.       /* If we have more, get the password */
  469.       if (*q)
  470.          {
  471.          /* Skip the space */
  472.          ++q;
  473.  
  474.          *q1++ = ' ';
  475.          *q1++ = '!';
  476.          while (*q)
  477.             {
  478.             *q1++ = *q++;
  479.             }
  480.          *q1++ = '\0';
  481.          }
  482.       }
  483.  
  484.    for (;;)
  485.       {
  486.       if ((rqname = n_frproc(buf, recno, (fsecs == 0)?0:1 )) != NULL)
  487.          {
  488.          /* If this is an update request, then check it out */
  489.          if (!stat (rqname, &st))
  490.             {
  491.             if (st.st_atime - timezone <= fsecs)
  492.                {
  493.                continue;
  494.                }
  495.             }
  496.          strcpy (reqs, rqname);
  497.          return (1);
  498.          }
  499.       else
  500.          {
  501.          q = buf;
  502.          while ((*q) && !isspace (*q))
  503.             ++q;
  504.          *q = '\0';
  505.          if (save_rec == -1)
  506.             status_line("!No files matched '%s'", buf);
  507.          reqs[0] = '\0';
  508.          return (2);
  509.          }
  510.       }
  511. }
  512.  
  513.